<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
    String path = request.getContextPath();
%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="copyright" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<title>验证核销</title>
<link href="<%=path%>/favicon.ico" rel="shortcut icon">
<link href="https://cdn.jsdelivr.net/gh/bootcdn/BootCDN/ajax/libs/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css"
	href="<%=path%>/css/marketing/public.css" />
	<link rel="stylesheet" type="text/css" href="<%=path%>/css/marketing/marketing.css" />
	<link rel="stylesheet" type="text/css" href="<%=path%>/css/marketing/activity.css" />
	<link rel="stylesheet" type="text/css" href="<%=path%>/css/marketing/style_list.css" />  
    <link rel="stylesheet" type="text/css" href="<%=path%>/css/marketing/custom.css" />
	<link href="<%=path%>/hplus/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
	<link href="<%=path%>/hplus/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
	<link href="<%=path%>/hplus/css/plugins/iCheck/custom.css" rel="stylesheet">
	<link href="<%=path%>/hplus/css/animate.min.css" rel="stylesheet">
	<link href="<%=path%>/hplus/css/style.min862f.css?v=4.1.0" rel="stylesheet">  
	<link href="<%=path%>/css/mushroom.css" rel="stylesheet">
	<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.16/css/jquery.dataTables.min.css" rel="stylesheet">
	<style type="text/css">
		 .input_form{
		 	margin-top:-10px;
		 }
	</style>
	
	
<link rel="stylesheet" type="text/css" href="<%=path%>/hplus/js/plugins/sweetalert/sweetalert2.min.css">

 
</head>
<body class="gray-bg">
	<div class="wrapper wrapper-content animated fadeInRight">
	<div class="container-fluid">
		
		 
		 <div class="row">
		 
		 <div class="col-sm-12">
		   <div class="ibox">
		   
		    <div class="ibox-content text-center">
		    
		    <h2>验证核销</h2>
		    
		    <div class="col-md-12" style="padding-left: 0px;margin-bottom: 15px;">
				<div class="col-md-12 text-right" style="padding-left: 0px;">
					<label class="col-sm-1 control-label" style="padding-top: 17px;padding-left: 0px;">移动端地址：</label>
					<div class="col-md-4" style="padding-top:10px;padding-left:0px;">
						<div class="input-group" style="padding-left:0px;">
							<input type="text" id="urlHref" readonly="readonly" class="form-control" value="" autocomplete="off">
							<span class="input-group-btn">
                             			<button type="button" class="btn btn-primary" onclick="coypUrl();">复制链接</button>
							</span>
						</div>
					</div>
					</div>
			</div>
		   <div class="search-form" style="margin-top: 15px;">
                        <div class="input-group">
                        <span class="input-group-addon" id="tenantNum">00-</span>
                            <input type="text" id="bian" style="font-size: 20px;font-weight: 400;" placeholder="请输入核销编码" name="search" class="form-control input-lg" value="">
                            <div class="input-group-btn">
                            	<shiro:hasPermission name="operate_write_off_verifiy:write_off">
                                <button id="s_verify_btn" class="btn btn-lg btn-primary d_j_submit" style="margin-left: 15px;" type="button">验证</button>
                                </shiro:hasPermission>
                            </div>
                        </div>
                    </div>
		    </div>
		   </div>   
		 </div>     

			<div class="col-md-12">
			
			 <form action="" class="form-inline">
			    <div class="form-group col-sm-6">
			       <label>请输入核销编码</label>
			       <input class="form-control" type="text" id = "shou"  maxlength="44"/>
			        <button onclick="func_dataTableReload()" type="button" class="btn btn-primary">搜索
                        </button>
			    </div>
			   <!--  <div class="form-group col-sm-3" style="margin-left:-20px">
			        <button id="phone" type="button" class="btn btn-primary">搜索
                        </button>
			    </div> -->
			    <%-- <div class="form-group col-sm-7">
			        <button id="phone" type="button" class="btn btn-w-m btn-info pull-right" onclick="window.location.href='<%=path%>/api/bm/ui/social_coupon'">优惠券管理</button>
			    </div> --%>
			 </form> 

			</div>
			<div class="col-md-12 " style="margin-top: 15px;">
			 <div class="ibox-title">
					  <h4>验证核销记录</h4>
					</div>
				<div class="k_record" style="margin-bottom:15px">
				   
					<table id="myTable" class="table table-bordered white-bg ">
						<thead>
							<tr>
								<th>手机号</th>
								<th>优惠券名</th>
								<th>核销时间</th>
								<th>编码</th>
								<th>核销人员</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody id = "shu" >
							
						</tbody>
					</table>
					
				
				</div>
				<div class="m_xpages" style="width:100%;margin:0;">
					<div class="mian">
						<span>显示行数</span> <select><option>10</option>
							<option>15</option>
							<option>20</option></select> <span>共0条</span> <span>0/0页</span> <a
							href="javascript:;" class="prev">上一页</a> <a href="javascript:;"
							class="next" >下一页</a> <span>前往</span> <input type="text" value="1"
							class="text"> <span>页</span>
					</div>
				</div>
			</div>
			
		</div>
		</div>
	</div>
	
	
	
	
	<!-- 验证成功 -->
	<div class="s_popup3" style="z-index:1">
		<div class="issue3">
			<span><img src="<%=path%>/images/marketing/close.png" /></span>
			<h4>
				<img src="<%=path%>/images/marketing/s_tick.png" />验证成功
			</h4>
			<p>请记录消费金额及详情</p>
			<ul class="fix">
				<li><span>消费金额</span>
					<div class="s_input_box">
						<input onkeyup="num(this)" maxlength="9" type="text" id = "bm_jine" placeholder="有效金额只能含有2位小数" onchange="addDecimalPoint()"/>
					</div></li>
				<li><span>个人偏好</span>
					<div class="s_input_box">
						<input type="text" id = "bm_xihao" placeholder="建议30字以内"/> <i>如：最喜欢的菜，或者对什么最满意</i>
					</div></li>
			</ul>
			<ol class="fix">
				<li><a href="javascript:;" class="s_cancel" id= "bm_quxia">取消</a></li>
				<li><a href="javascript:;" class = "bm_que">确定</a></li>
			</ol>
		</div>
	</div>

	<!-- 反核销信息确认 -->
	<div class="s_popup" style="z-index:1">
		<div class="issue">
			<span><img src="<%=path%>/images/marketing/close.png" /></span>
			<h4>反核销信息确认</h4>
			<ul class="fix">
				<li><span><i>*</i>反核销原因</span>
					<div class="s_input_box"> 
						<textarea id = "bm_fanhe" placeholder="建议30字以内"></textarea>
					</div></li>
<!-- 				<li><span><i></i>操作人</span> -->
<!-- 					<div class="s_input_box"> -->
<!-- 						<input type="text" id = "bm_cao"/> -->
<!-- 					</div></li> -->
			</ul>
			<ol class="fix">
				<li><a href="javascript:;" class="s_cancel" id = "bm_qux">取消</a></li>
				<li><a href="javascript:;" class="s_next_step" id = "bm_fanque">下一步</a></li>
			</ol>
		</div>
	</div>

	<!-- 反核销成功 -->
	<div class="s_popup1">
		<div class="issue1" id = "bm_wanc">
			<span><img src="<%=path%>/images/marketing/close.png" /></span>
			<h4>
				<img src="<%=path%>/images/marketing/s_tick.png" />反核销成功
			</h4>
			<div class="s_con" id ="s_cc">
				<!-- <i>编码为</i>
				<p>696244934567</p>
				<em>优惠券反核销成功！</em> -->
			</div>
			<p>
				<a href="javascript:;" class="s_finish">完成</a>
			</p>
		</div>
	</div>

	<!-- 验证核销 -->
	<%-- <div class="s_popup2">
		<div class="issue2">
			<span><img src="<%=path%>/images/marketing/close.png" /></span>
			<div class="bm_con">
			</div>
			<ol class="fix">
				<li><a href="javascript:;" class="s_cancel">取消</a></li>
				<li><a href="javascript:;" class="k_verify">验证</a></li>
			</ol>
		</div>
	</div> --%>

	<!-- 验证失败 -->
	<div class="s_popup4">
		<div class="issue4">
			<span><img src="<%=path%>/images/marketing/close.png" /></span>
			<h4>
				<img src="<%=path%>/images/marketing/s_caution.png" />验证失败
			</h4>
			<div class="sm_con">
				<p>不存在该优惠券</p>
			</div>
			<p>
				<a href="javascript:;" id = "bm_wc">确定</a>
			</p>
		</div>
	</div>
	
	 <div class="modal inmodal fade" id="myModal5" tabindex="-1" role="dialog"  aria-hidden="true">
         <div class="modal-dialog">
             <div class="modal-content">
	              <div class="modal-header">
                      <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                      <h6 class="modal-title">优惠券信息</h6>
                  </div>
                 <div class="modal-body">
                	 <div class="row">
		                 <form method="get" class="form-horizontal m-t text-center">
		                      <div class="form-group col-md-12">
	                              <h3 class="col-sm-6 text-left"  >券的信息</h3>
	                          </div>
			                  <div class="form-group col-md-12 input_form" style="margin-top:-10px">
	                              <p class="col-sm-3 text-right"  >券名：</p>
	                              <p id="couponName" class="col-sm-6 text-left"  ></p>
	                          </div>
	                          <div class="form-group col-md-12 input_form" style="margin-top:-10px">
	                              <p class="col-sm-3 text-right"  >种类：</p>
	                              <p id="couponType" class="col-sm-6 text-left"  ></p>
	                          </div>
	                          <div class="form-group col-md-12 input_form">
	                              <p class="col-sm-3 text-right"  >券码：</p>
	                              <p id="couponCode" class="col-sm-6 text-left"  ></p>
	                          </div>
	                          <div class="form-group col-md-12 input_form">
	                              <p class="col-sm-3 text-right"  >满减规则：</p>
	                              <p id="limitPrice" class="col-sm-6 text-left"  ></p>
	                          </div>
	                          <div class="form-group col-md-12 input_form">
	                              <p class="col-sm-3 text-right"  >有效期：</p>
	                              <p id="validityPeriod" class="col-sm-9 text-left"  ></p>
	                          </div>
	                           <div class="form-group col-md-12 input_form">
	                              <p class="col-sm-3 text-right"  >使用时段：</p>
	                              <p id="useTime" class="col-sm-6 text-left"  ></p>
	                          </div>
		                 </form>
		                  <form method="get" class="form-horizontal m-t text-center">
		                      <div class="form-group col-md-12 ">
	                              <h3 class="col-sm-6 text-left"  >人的信息</h3>
	                          </div>
			                  <div class="form-group col-md-12 input_form">
	                              <p class="col-sm-3 text-right"  >姓名：</p>
	                              <p id="customerName" class="col-sm-6 text-left"  ></p>
	                          </div>
	                          <div class="form-group col-md-12 input_form">
	                              <p class="col-sm-3 text-right"  >电话：</p>
	                              <p id="customerPhone" class="col-sm-6 text-left"  ></p>
	                          </div>
	                          <div class="form-group col-md-12 input_form">
	                              <p class="col-sm-3 text-right"  >领取时间：</p>
	                              <p id="receiveTime" class="col-sm-6 text-left"  ></p>
	                          </div>
	                         
		                 </form>
	                 </div>
                 </div>
                 <div class="modal-footer text-center">
                      <button type="button" class="btn btn-white" data-dismiss="modal">取消</button>
                      <button type="button" class="btn btn-primary k_verify">验证</button>
                  </div>
             </div>
         </div>
     </div>
	
	
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.16/js/jquery.dataTables.min.js"></script>
	<script type="text/javascript" src="<%=path%>/js/marketing/jquery.cookie.js"></script>   
	<script type="text/javascript" src="<%=path%>/js/marketing/lengthlimit.js"></script>
	<script type="text/javascript" src="<%=path%>/js/marketing/InputLimitedByidandlength.js"></script>
	<script src="<%=path%>/hplus/js/plugins/sweetalert/sweetalert2.min.js"></script>
	<script type="text/javascript" src="<%=path%>/js/marketing/dialog.js"></script>
	<script type="text/javascript" src="<%=path%>/js/marketing/validation.js"></script>
	<script src="<%=path%>/hplus/js/bootstrap.min.js?v=3.3.6"></script>
    <script src="<%=path%>/hplus/js/content.min.js?v=1.0.0"></script>
    <script src="<%=path%>/hplus/js/plugins/iCheck/icheck.min.js"></script>
	<script type="text/javascript" src="<%=path%>/js/loading.js"></script>
	<script>
      $('.k_box3 table a').click(function(){
        $('.s_popup,.issue').show();
      });

      $('.s_finish').click(function(){
    	//  window.location.reload();
    	  var ssid = '#line'+coupon_code;
    	  $('.s_popup1,.issue1').hide();
    	  $('.s_popup,.issue').hide();
    	  $(ssid).remove();
    	  window.location.reload();
      });
      
      //点击取消后消失(核销验证)
      $('#bm_quxia').click(function(){
    	  $('.s_popup3,.issue3').hide(); 
      }); 
     
      $('.s_cancel').click(function(){
       	 $('#bian').val('');
       	 window.location.reload();
    	 $('.s_popup2,.issue2').hide();
      });
      
      //点击确定后消失
      $('#bm_wc').click(function(){
    	  window.location.reload();
    	  $('.s_popup4,.issue4').hide();
      });
    //反核销消失按钮
	      $('#bm_qux').click(function(){
	    	  $('.s_popup,.issue').hide(); 
	      });
      //验证成功（把优惠券数据插入核销表）
     /*  $('.k_verify').click(function(){
         $('.s_popup2,.issue2').hide();
       //  $('.s_popup3,.issue3').show(); 
       });   */

      $('.issue > span').click(function(){
        $('.s_popup,.issue').hide();
      });
      $('.issue2 > span').click(function(){
        $('.s_popup2,.issue2').hide();
      });
      $('.issue3 > span').click(function(){
        $('.s_popup3,.issue3').hide();
      });
      $('.issue4 > span').click(function(){
        $('.s_popup4,.issue4').hide();
      });
      $('.issue1 > span').click(function(){
        $('.s_popup1,.issue1').hide();
      });
    </script>
	<script type="text/javascript">

	
	var activity_id;
	var customer_phone;
	var coupon_name;
	var coupon_code;
	var coupon_id;
	var verification_id;
	var customer_id;
	var activity_name;
	
	//分页
    var startIndex = 0;
    var pageSize = 10;
    var currentPage = 1;
    var pageCount = 0;
    var listIndex=0;
    var socialCouponId=0;
	var access_token=$.cookie('access_token');
	var cid=$.cookie('cid');
	var uid=$.cookie('uid');
	var user_name = $.cookie('user_name');
	cid = '${cid}';
	
	if(!isNaN(parseInt(cid))){
		cid = parseInt(cid);
		if(cid < 10){
			cid = "0" + cid;
		}
	}
	
	$(function(){
		$("#urlHref").val("http://"+window.location.host+"/view/ui/h5Login");
 		getTenantNum();
    	inputlimited("#bm_jine",15);
    	inputlimited("#bm_xihao",30);
    	inputlimited("#bm_fanhe",30);
    	inputlimited("#bm_cao",20);
    	//$('#tenantNum').text(cid);
    });
	
	function getTenantNum(){
		var url="<%=path%>/coupon/ajaxGetCouponDefaultCode";
		$.post(url,function(data) {
			$('#tenantNum').html(data+"—");
		});
	}
	  //---------->验证（查询优惠券信息）
	 $('#s_verify_btn').click(function(){		
		//获取验证编码
   	  var coupon_code =$('#bian').val();
		if(coupon_code.length <= 11){
			// coupon_code = cid + coupon_code;
		}
   	  var params = {
   		  "couponCode" : coupon_code	    		 
   	  };   	 
   	  $.ajax({
   		  type : "post",
   		  url : path+"/coupon/ajaxGetCouponSendRecordByDto",
   		  dataType : "json",
   		  data : params,
   		  async:false,
   		  success : function(data){ 
   			  $('.bm_con').html("");
   			      var b = data.status;
				  var b2 = data.message;	
				  
				  if(200 == b){   	
					 var couponInfo= data.data;
					 coupon_id=couponInfo.couponId;
		   			 $("#couponName").html(couponInfo.name);
		   			 $("#couponCode").html(coupon_code);
		   			 $("#couponPrice").html(couponInfo.faceValue);
		   			 
// 		   			 activity_name=couponInfo.activityName;
// 		   			 coupon_name=couponInfo.couponName;
// 		   			 customer_id=couponInfo.customer_id;
// 		   			 coupon_code=couponInfo.customer_id;
// 		   			 activity_id=couponInfo.activityId;
// 		   			 socialCouponId=couponInfo.socialCouponId;
		   			 //种类
		   			if(couponInfo.type==0){
		   				 $("#couponType").html("代金券");
		   			 }else if(couponInfo.type==1){
		   				$("#couponType").html("物品券");
		   			 }
		   			 
		   			 //满减
		   			 var limitPrice=couponInfo.limitPrice;
		   			 if(StringEmpty(limitPrice)&&limitPrice!=0){
		   				 $("#limitPrice").html("满"+limitPrice/100+"使用");
		   			 }else {
		   				$("#limitPrice").html("无");
		   			 }
		   			 //有效期
		   			 if(StringEmpty(couponInfo.validityPeriodType+"")&&couponInfo.validityPeriodType==0){
		   				 $('#validityPeriod').html(new Date(couponInfo.startTime).Format("yyyy-MM-dd")+" 至 "+new Date(couponInfo.endTime).Format("yyyy-MM-dd"));
		   			 }else if(StringEmpty(couponInfo.validityPeriodType+"")&&couponInfo.validityPeriodType==1){
		   				 $('#validityPeriod').html(new Date(couponInfo.createTime).Format("yyyy-MM-dd")+" 至 "+new Date(couponInfo.expiryDate).Format("yyyy-MM-dd"));
		   			 }else{
		   				 $('#validityPeriod').html("无");
		   			 }
		   			 
		   			 //适用时段
		   			 if(StringEmpty(couponInfo.useTimeType+"")&&couponInfo.useTimeType==0){
		   				$('#useTime').html("无");
		   			 }else if(StringEmpty(couponInfo.useTimeType+"")&&couponInfo.useTimeType==1){
		   				$('#useTime').html(couponInfo.periodTimeWeek+" "+couponInfo.periodTimeHour);
		   			 }else{
		   				 $('#useTime').html("无");
		   			 }
		   			 
	   				 if(StringEmpty(couponInfo.name)){
	   					 $("#customerName").html(couponInfo.customerName);
	   				 }else{
	   					$("#customerName").html("无");
	   				 }
	   				 
	   				 if(StringEmpty(couponInfo.customerPhone)){
	   					$("#customerPhone").html(couponInfo.customerPhone);
	   				 }else{
	   					$("#customerPhone").html("无");
	   				 }
		   			$("#receiveTime").html(new Date(couponInfo.receiveTime).Format("yyyy-MM-dd hh:mm:ss"));
		   			 
		   			 $("#myModal5").modal('show');
		   			  
		   	       }else if ("601" == b) {  
		   	    	    errorDialog("验证失败","不存在该优惠券");
			       }else if(b == "602"){
			    	    errorDialog("验证失败","该优惠券已消费");
			       }else/* if(b == "3")*/{
			    	   errorDialog("请输入优惠券码","");
			       } 			  
   		  }   		  
   	   }); 
     }); 
	  //点击确定消失(输入空优惠券码时)
	  $(document).on('click','#bm_wc',function(){
		  $('.s_popup4,.issue4').hide();
	  });
	  
	  //打叉消失(输入空优惠券码时)
	  $(document).on('click','.issue4 img',function(){
		  $('.s_popup4,.issue4').hide();
	  });
		 
	 //------------------>验证成功（把优惠券数据插入核销表）
	 $('.k_verify').click(function(){
		var coupon_code = $('#bian').val();
		var params = {
				"id" : coupon_id
		};			
		$.ajax({			
			type: "post",
			url : path+"/coupon/ajaxWriteoff",
			dataType : "json",
			data: params,
			async: false,
			success : function(data){		
				$("#myModal5").modal('hide');
				if(data.status == "200"){				
					verification_id=data.data;
					$('.s_popup3,.issue3').show();
				}else if(data.status=="602"){
					errorDialog("券码不存在","");
				}else if(data.status=="603"){
                    errorDialog("该优惠券已过期");
                }
				else if(data.status=="601"){
					errorDialog("该优惠券已核销，请勿反复核销");
				}
				func_dataTableReload();
			},
			error: function(data){
				errorDialog("操作出错，请重试");
          	  	window.location.reload();
            }
		});
	 });
	 var consumption_amount;
       //------------>验证成功（核销编辑）
       $('.bm_que').click(function(){
    	   //消费金额
    	   //个人偏好
    	   var consumption_preference=$('#bm_xihao').val();
    	   if(StringEmpty(consumption_amount)&&StringEmpty(consumption_preference)&&jiner(consumption_amount)){
    		   var params = {
        			 "access_token" : access_token,
       				 "cid" : cid,
       				 "uid" : uid,
        			 "id" : verification_id,
        			 "consumptionPreference" : consumption_preference,
        			 "consumptionAmount" : consumption_amount
        	   };
        	   $.ajax({
        		   type : "post",
        		   url : path+"/coupon/ajaxEditCouponSendRecord",
        		   dataType : "json",
    			   data : params,
    			   async:false,
    			   success: function(data){		
    				   if(data.status == 200){
    					   $('.s_popup3,.issue3').hide();					 
    					 //  window.location.reload();
    					   successDialog("操作成功！");
    				   }else{
    					   errorDialog("操作失败");
    					   $('.s_popup3,.issue3').hide();
    				   }
    				   window.location.reload();
    			   },
    			   error: function(data){
    	            	  errorDialog("操作出错，请重试");
    	              }
        	   });
    	   }else if(!StringEmpty(consumption_amount)&&!StringEmpty(consumption_preference)){
    		   errorDialog("请输入消费金额与个人偏好！！！");
    	   }else if(!StringEmpty(consumption_amount)){
    		   errorDialog("请输入正确的消费金额");
    	   }else if(!jiner(consumption_amount)){
    		   errorDialog("请输入正确的消费金额");
    	   }
    	   else{
    		   errorDialog("请输入个人偏好！！！");
    	   }
       });
       
       //判断消费金额是否为数字/^[1-9]\d*$/
       function jiner(money){ 
    	var reg =/^(0|[1-9][0-9]{0,9})(\.[0-9]{1,3})?$/;//正则表达式 
    	var result = reg.test(money);	//匹配
    	if(!result){
    		return false;
    	}else{
    		return true;
    	}
    }
       //点击查询
       $('#phone').click(function(){
    	   queryList();
       });
      //-------------->根据手机号或编码查询数据
      function queryList(){
    	  
    	  if(listIndex != 1){
    		  listIndex = 0;
    	  }
    	  listIndex = 1 ;
    	//手机号
   	   var mobile = $('#shou').val();   
   	   //编码
   	   var coupon_code = $('#shou').val();	
   	   if(StringEmpty(mobile)||StringEmpty(coupon_code)){
   		      var url = "<%=path%>/verification/ajaxVerifyList";
		  	  $.post(url,{
	  		         "access_token" : access_token,
					 "cid" : cid,
					 "uid" : uid,
		 			 "customerPhone" :mobile,
		 			 "couponCode" : coupon_code,
		 			 "startIndex" : startIndex,
				 	 "pageSize" : pageSize 
			 			 
		  	  },function(data){
		  		  
		  		  if(data.error_code == "0"){
		  			  page(data.totalCount); 
		  			  listHtml(data.data);
		  		  }else if(data.error_code == "1"){
		  			errorDialog("该优惠券不可反核销或不存在该优惠券");
						}
		  	  });
   	   }else{
   		promptDialog("请输入优惠券或手机号码查询！");
   	     }
    	  
      }
      
      $(function(){
//     	  queryAll(); 
      });
    //查询所有核销记录
      function queryAll(){
    	if(listIndex != 2){
    		listIndex = 0;
    	}
    	listIndex = 2;
   	   var url = "<%=path%>/verification/ajaxVerifyList";
   	   $.post(url,{
   		        "access_token" : access_token,
				"cid" : cid,
				"uid" : uid,
				"startIndex" : startIndex,
				"pageSize" : pageSize 
   	   },function(data){
   		   
   		   if(data.error_code == "0"){
   			   page(data.totalCount);
   			   listHtml(data.data);
   		   }
   	   });
      }
      
      function listHtml(data){
    	  var html = '';
    	  for(var i in data){
    		  html += '<tr id="line'+data[i].couponCode+'"><td>'+ data[i].customerPhone + '</td><td>'
  			+ data[i].couponName + '</td><td>'
  			+ data[i].createTimeStr + '</td><td >'
  			+ data[i].couponCode + '</td><td><a href="javascript:;" cd="'+data[i].couponCode+'" couponId="'+data[i].couponId+'" class="bm_fan" acid="'+data[i].activityId+'" cuid="'+data[i].customerId+'"><font color="#1ab394">反核销</font></a></td>'; 									
    	  }
    	    $('#shu').html(html);
      }
      
       <%-- $('#phone').click(function(){
    	   //手机号
    	   var mobile = $('#shou').val();   
    	   //编码
    	   var coupon_code = $('#shou').val();	
    	   //请求参数
    	   var params = {
    			 "access_token" : access_token,
   				 "cid" : cid,
   				 "uid" : uid,
  	 			 "mobile" :mobile,
  	 			 "coupon_code" : coupon_code	 			 
  	 	 };    	  
    	  $.ajax({ 	
  		            type: "post",  		      
    		        url : "<%=path%>/verification/list",    		 
					dataType : "json",
					data : params,
					async:false,
					success : function(data) {
						$('#shu').html("");
						var d = data.error_code;
						var d2 = data.message;
						var d3 = data.data;
						var str = "";	
						if(d == 0){
							for (i in d3) {					
								str += '<tr id="line'+d3[i].coupon_code+'"><td>'+ d3[i].mobile + '</td><td>'
										+ d3[i].coupon_name + '</td><td>'
										+ d3[i].w_time + '</td><td >'
										+ d3[i].coupon_code + '</td><td><shiro:hasPermission name="bm_write_off_reverse_button"><a href="javascript:;" cd="'+d3[i].coupon_code+'" couponId="'+d3[i].coupon_id+'" class="bm_fan" acid="'+d3[i].activity_id+'" cuid="'+d3[i].customer_id+'">反核销</a></shiro:hasPermission></td>'; 									
							}					
							$('#shu').html(str);	
						}else if(d==1){
							showDialog("该优惠券不可反核销或不存在该优惠券，请重新确认！");
						}
					  }
					}); 
				}); --%>
      
      //----------->反核销
       $(document).on('click','.bm_fan',function(){	
    	   couponId = $(this).attr("couponId");
		   coupon_code = $(this).attr("cd");
		   $('#bm_cao').val(user_name);
		   activity_id = $(this).attr("acid"); 
		   customer_id = $(this).attr("cuid");
	 			$('.s_popup,.issue').show();
	 			$('#bm_fanhe').val('');
	 			$('#bm_cao').val(user_name);
				//$('#bm_cao').val('');  
		       });
      
        
       //----------->反核销成功
		$('#bm_fanque').click(function(){
			var reverse_reason = $('#bm_fanhe').val();
		//	activity_name = $(this).attr("acname");
		    if(StringEmpty(reverse_reason)){
		    	var params = {
		        		"reverseReason" : reverse_reason,
		        		"id" : couponId
		        };	 		      
		        $.ajax({
		        	  type:"post",
		              url:path+"/coupon/ajaxReverseWriteoff",
		              data:params,
		              dataType:"json",
		              async:false,
		              success:function(data){	
		            	 if(data.status == "200"){
		            		//反核销信息确认
		         			$('.s_popup,.issue').hide();
		            		$('.s_popup1,.issue1').show();
		            		var str = "";
		            		str += '<i>编码为</i><p>' +coupon_code+ '</p><em>优惠券反核销成功！</em>';
		            		$('#s_cc').html(str);	
		            	 }else if(data.status == "601"){
		            		errorDialog("请勿重复反核销"); 
		            		$('.s_popup,.issue').hide();
		            		$('.s_popup1,.issue1').hide();
		            	 }else if(data.status == "602"){
			            		errorDialog("券码不存在"); 
			            		$('.s_popup,.issue').hide();
			            		$('.s_popup1,.issue1').hide();
			             }else{
// 			            	errorDialog("内部错误"); 
			            	$('.s_popup,.issue').hide();
			            	$('.s_popup1,.issue1').hide();
			           	  }   
		            	  func_dataTableReload();
		              },
		              error: function(data){
		            	  errorDialog("操作出错，请重试");
		              }
		        });
		    }else if(!StringEmpty(reverse_reason)){
		    	promptDialog("请输入反核销原因！！！");
		    }
		});
       
				$(".m_xpages select").change(function(){
			 		pageSize = Number($(this).val());
			 		if(listIndex == 1){
			 			queryList();
			 		}else if(listIndex == 2){
			 			queryAll();
			 		}
			 	});
			 	
			 	$(".m_xpages a.prev").click(function(){	 		
			 		$('.next').html('<font color="black">下一页</font>');
			 		if(currentPage > 1){
			 			currentPage--;
			 			startIndex -= pageSize;	 	
			 			if(currentPage == 1){
				 			$('.prev').html('<font color="#bdbdbd">上一页</font>');
			 			}
			 			if(listIndex == 1){
				 			queryList();
				 		}else if(listIndex == 2){
				 			queryAll();
				 		}
			 		}
			 	});
			 	
			 	$(".m_xpages a.next").click(function(){
			 		$('.prev').html('<font color="black">上一页</font>'); 
			 		if(currentPage < pageCount){
			 			currentPage++;
			 			startIndex += pageSize;	
			 			if(currentPage == pageCount){
				 			$('.next').html('<font color="#bdbdbd">下一页</font>');
				 		}
			 			if(listIndex == 1){
				 			queryList();
				 		}else if(listIndex == 2){
				 			queryAll();
				 		}
			 		}
			 	});
			 	
			 	$(".m_xpages :text").keyup(function(e){
					if(e.keyCode==13){
						var pageGo = $(this).val();
						if(/^[0-9]+$/.test(pageGo)){
							pageGo = Number(pageGo);
							if(pageGo<1 || pageGo>pageCount){
								showDialog('请输入合法页数');
							}else if(pageGo != currentPage){
								startIndex = (pageGo -1) * pageSize ;	
								if(listIndex == 1){
						 			queryList();
						 		}else if(listIndex == 2){
						 			queryAll();
						 		}
							}
						}else{
							showDialog('请输入合法页数');
						}
					}
				});
			 	
			  function page(totalCount){
				pageCount = totalCount/pageSize;
		 		if (totalCount % pageSize > 0)
		 			pageCount++;
		 		pageCount = parseInt(pageCount);
		 		currentPage =  startIndex / pageSize + 1;
		 		currentPage = parseInt(currentPage);
		 		if(currentPage == 1){
		 			$(".prev").addClass("pageDisable");
		 		}else{
		 			$(".prev").removeClass("pageDisable");
		 		}
		 		
		 		if(currentPage == pageCount || pageCount == 0){
		 			$(".next").addClass("pageDisable");
		 		}else{
		 			$(".next").removeClass("pageDisable");
		 		}
		 		
		 		$(".m_xpages>.mian>span:eq(1)").text('共'+totalCount+'条');
		 		$(".m_xpages>.mian>span:eq(2)").text(currentPage+'/'+pageCount+'页');
			}

			  
			  
			function addDecimalPoint(){
				consumption_amount=$('#bm_jine').val();
				if(consumption_amount.split(".").length==1){
					$('#bm_jine').val(consumption_amount+".00");
				}else{
					if(!StringEmpty(consumption_amount.split(".")[1])){
						consumption_amount=consumption_amount.split(".")[0];
						$('#bm_jine').val(consumption_amount.split(".")[0]+".00");
					}
				}
			}	
		//判断字符串是否为空
		function StringEmpty(content) {
			if (content == undefined || content == "" || content == null) {
				return false;
			} else {
				return true;
			}
		}
		 function showDialog(title){
				$('#dialog_title').html('<img src="<%=path%>/images/marketing/s_tick.png"/>'+title+''); 
				$('.s_popup_delect2,.s_consum').show().delay(800).fadeOut();
			}
	</script>
</body>
<script type="text/javascript">
$.fn.dataTable.ext.errMode = 'none';
var myDataTable;
var path = "<%=path%>";
var couponId = 0;	//优惠券发送记录id


$(function(){
	init();
});

function init(){
	myDataTable = dataTable();
}

//反核销原因弹框
function func_reverseReason(id,couponCode){
	couponId = id;
	coupon_code = couponCode;
	$('.s_popup,.issue').show();
}

function func_dataTableReload() {
	myDataTable.ajax.reload();
}

function func_AjaxUrl() {
    return path + "/coupon/ajaxCouponPageList";
}

function func_columns() {
    var jsonArr = [
        {"data": "customerPhone"},
        {"data": "couponName"},
        {"data": "writeOffTime"},
        {"data": "couponCode"},
        {"data": "username"},
        {"data": "id"},
    ];
    return jsonArr;
}

function func_ajaxData() {
    var jsonObject = {};
    jsonObject.isUsed = 1;
    if($.trim($("#shou").val()) != ""){
    	jsonObject.couponCode = $.trim($("#shou").val());
    }
    return jsonObject;
}

function dataTable() {
    return $('#myTable').DataTable({
        processing: true,
        ordering: false,
        searching: false,
        info: true,
        autoWidth: false,
        lengthChange: false,
        language: {
            emptyTable: '没有数据表',
            info: '从第 _START_ 到第 _END_ 条数据；总共有 _TOTAL_ 条记录',
            infoEmpty: '没有数据',
            lengthMenu: '每页显示 _MENU_ 条记录',
            loadingRecords: '正在加载数据....',
            processing: '正在处理数据....',
            zeroRecords: '没有找到匹配的记录',
            paginate: {
                first: '首页',
                previous: '前页',
                next: '后页',
                last: '尾页'
            }
        },
        order: [[1, 'desc']],
        pageLength: 10,
        pagingType: 'full_numbers',
        columnDefs: [{
            render: function (data, type, full) {
                var result = "";
                if (data != null) {
                    result = new Date(data);
                    result = result.Format("yyyy-MM-dd hh:mm:ss");
                }
                return result;
            },
            targets: 2
        },{
            render: function (data, type, full) {
                var result = "";
                <shiro:hasPermission name="operate_write_off_verifiy:contrary_write_off">
                result = '<a onclick="func_reverseReason(\''+data+'\',\''+full.couponCode+'\')" href="javascript:void(0)" style="color:1ab394;">反核销</a>';
                </shiro:hasPermission>
                return result;
            },
            targets: 5
        }],
        columns: func_columns(),
        serverSide: true,
        ajax: {
            contentType: 'application/json;charset=utf-8',
            type: 'POST',
            url: func_AjaxUrl(),
            data: function (d) {
                d.extra_search = func_ajaxData();
                return JSON.stringify(d);
            }
        }
    });
}
Date.prototype.Format = function (fmt) { //author: meizz 
    var o = {
        "M+": this.getMonth() + 1, //月份 
        "d+": this.getDate(), //日 
        "h+": this.getHours(), //小时 
        "m+": this.getMinutes(), //分 
        "s+": this.getSeconds(), //秒 
        "q+": Math.floor((this.getMonth() + 3) / 3),
        "S": this.getMilliseconds() //毫秒 
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}
//复制网址
function coypUrl(){
    var val=document.getElementById("urlHref");
    val.select(); // 选择对象
    document.execCommand("Copy"); // 执行浏览器复制命令
    successDialog("复制成功！");
}
</script>
</html>